import { Button, Statistic, Tooltip,AutoComplete, message, Row, Col, Card, Input, Form, InputNumber } from 'antd';
import React, {
  useState
} from 'react';
import { PageContainer } from '@ant-design/pro-layout';

import { initFileUploadTask } from './service';

const TableList: React.FC<{}> = () => {

  const [form] = Form.useForm();
  const [lock,setLock] = useState(false)
  const onFinish = async () => {
    let param = form.getFieldsValue();
    console.log(param);
    if (!param.activityId) {
      message.error('活动ID不能为空')
      return
    }
    setLock(true)
    setTimeout(()=>{
      setLock(false)
    },5000)
   const res = await initFileUploadTask(param)
   if(res.code === 200){
     message.success('已加入下载列表，5s后可再次导出数据')
   } else {
     message.error(res.message)
   }
  }

  return (
    <PageContainer>
      <Card style={{'marginBottom':'0'}}>
        <Form form={form} onFinish={onFinish} >
          <Row gutter={[16,16]} >
          <Col span={8} >
             <Form.Item
              name="activityId"
              label="课程ID"
              >
              <InputNumber placeholder="请输入" min={0} style={{ width: '100%' }}/>
            </Form.Item>
          </Col>

            <Col span={8}>
              <Form.Item style={{textAlign: 'right'}}>
                <Button type="primary" disabled={lock} htmlType="submit" style={{marginRight:'10px'} }>
                 导出数据
                </Button>
              </Form.Item>
            </Col>
          </Row>
        </Form>
      </Card>
    </PageContainer>
  );
};

export default TableList;
